<?php
namespace Admin\Controller;

use Common\Controller\AdminbaseController;

class UserMsgController extends AdminbaseController {
    public function index() {
    	$p=1;
    	if (isset($_GET['p'])){
    		$p=$_GET['p'];
    	}
    	$Model = M();
    	$query=$Model->query("SELECT count(id) as count FROM `hua`  ");
    	$count=$query[0]['count'];
    	$page = $this->page($count, 10, $p);
    	$queryData=$Model->query("SELECT * FROM `hua` order by id desc  limit ".(($p-1)*10).",10 ");
        $queryName=array();
    	foreach ($queryData as $v){
    		$openid=$v['openid'];
    		$queryUser=$Model->query("SELECT name FROM `users` where openid='".$openid."' limit  0,1 ");
    		$queryName[$openid]=base64_decode($queryUser[0]['name']);
    	}

    	$this->assign("page", $page->show('Admin'));
    	$this->assign("queryData", $queryData);
    	$this->assign("queryName", $queryName);
        $this->display();
    }
  
    public function delete() {
    	if (isset($_GET['id'])){
    		$id=$_GET['id'];
    		$Model = M();
    		$deleter = M("ua", 'h');
    		$deleter->where('id='.$id)->delete();
    		$info=json_encode(array('state'=>'success','info'=>'删除成功','referer'=>'admin.php?g=Admin&m=Contactsys&a=index'));
    		echo $info;
    	}
    }
    
    public function edit() {
    	if (isset($_GET['id'])){
    		$id=$_GET['id'];
    	}else{
    		exit;
    	}
    	$Model = M();
    	if (isset($_GET['id'])){
    		if ('yes' == $_GET['t']){
    			$info=$Model->execute("update `hua` set audit='yes' where id='".$id."'  ");
    		}else{
    			$info=$Model->execute("update `hua` set audit='not' where id='".$id."'  ");
    		}
    	}
    	
    	header('Location: admin.php?g=Admin&m=UserMsg&a=index');
    	exit;
    	//$this->success('操作完成','admin.php?g=Admin&m=UserMsg&a=index',1);
    	 
    }
     
    
}
